package com.baizhi.controller;

import com.baizhi.exception.UserNotFoundException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class DemoController {
    private static final Logger logger = LoggerFactory.getLogger(DemoController.class);

    @RequestMapping("demo")
    public String demo() {
        try {
            logger.debug("demo ok...");
            int n = 1 / 0;  // 报错，算数异常
        } catch (Exception e) {
            e.printStackTrace();
            return "500";
        }
        return "hello";
    }

    @RequestMapping("demo1")
    public String demo1() {
        logger.debug("demo ok...");
        int n = 1 / 0;  // 报错，算数异常
        return "hello";
    }

    @RequestMapping("login")
    public String login(String username, String password) {
        logger.debug("username：{}", username);
        logger.debug("password：{}", password);
        if ("xiaochen".equals(username) && "123".equals(password)) {
            return "hello";
        } else {
            throw new UserNotFoundException("用户名不正确!!!");
        }
    }
}
